//
//  SeriesTableViewController.m
//  Our Big Demo
//
//  Created by 张立强 on 16/3/25.
//  Copyright © 2016年 WJP. All rights reserved.
//

#import "SeriesTableViewController.h"
#import "SeriesTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "GiveMeHleper.h"
#import "SeriesModel.h"
@interface SeriesTableViewController ()
@property (nonatomic,strong) NSMutableArray *allDataArray;
@end

@implementation SeriesTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self handleData];
}
- (void)handleData{
    self.allDataArray = [NSMutableArray array];
    
    [[GiveMeHleper defaultCDHttpHelper]get:@"http://app.vmoiver.com/apiv3/series/getList?p=1" params:nil success:^(id responseObj) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObj options:NSJSONReadingMutableLeaves error:nil];
        for (NSDictionary *dict in dic[@"data"]) {
            NSLog(@"%@",dict);
            SeriesModel *model = [SeriesModel new];
            [model setValuesForKeysWithDictionary:dict];
            [self.allDataArray addObject:model];
        }
        NSLog(@"解析数据OK！");
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        NSLog(@"解析数据Fail");
    }];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.allDataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return self.view.frame.size.width*0.5 + 110;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SeriesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Series" forIndexPath:indexPath];
    SeriesModel *model = self.allDataArray[indexPath.row];
    //设置图片
    [cell.MovieImage sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:[UIImage imageNamed:@"Movie123"]];
    cell.MovieName.text = model.title;
    cell.MovieDetailLable.text = model.content;
    
    //已更新几集，几人订阅
    NSString *str1 = @"已更新至第";
    NSString *str2 = @"集  ";
    NSString *str3 = @"已订阅";
    NSString *str4 = [str1 stringByAppendingString:model.update_to];
    NSString *str5 = [str4 stringByAppendingString:str2];
    NSString *str6 = [str5 stringByAppendingString:model.follower_num];
    NSString *str = [str6 stringByAppendingString:str3];
    cell.UpdataLable.text = str;
    
    return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
